package com.zhz.controller;

import com.zhz.domain.SysMenu;
import com.zhz.model.R;
import com.zhz.model.RolePrivilegesParam;
import com.zhz.service.SysRolePrivilegeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：zhz
 * @date ：Created in 2020/12/24
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 * @description:
 **/
@Api(tags = "角色权限的配置")
@RestController
public class SysRolePrivilegeController {
    @Autowired
    private SysRolePrivilegeService sysRolePrivilegeService;

    @GetMapping("/roles_privileges")
    @ApiOperation(value = "查询角色的权限列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId",value = "角色的id")
    })
    public R<List<SysMenu>> findSysMenuAndPrivileges(Long roleId){
        return R.ok(sysRolePrivilegeService.findSysMenuAndPrivileges(roleId));
    }

    @GetMapping("/grant_privileges")
    @ApiOperation(value = "授予角色某种权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rolePrivilegesParam" ,value = "rolePrivilegesParam json数")
    })
    public R grantPrivileges(@RequestBody RolePrivilegesParam rolePrivilegesParam){
        return sysRolePrivilegeService.grantPrivileges(rolePrivilegesParam)?R.ok():R.fail("授予失败")  ;
    }
}
